package com.zzptc.db;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import com.sun.xml.internal.bind.v2.runtime.output.C14nXmlOutput;

public class DB implements DBI {
	Connection conn;
	private final String url="jdbc:mysql://localhost:3306/shopping?useUnicode=true&characterEncoding=utf-8";
	private final String username="root";
	private final String password="123456";
	
	public DB(){
		try {
			Class.forName("com.mysql.jdbc.Driver");
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	public void closeConn() throws SQLException {
		// TODO Auto-generated method stub
		if(conn!=null&&!getConn().isClosed()){
			conn.close();
		}
	}

	public Connection getConn() throws SQLException {
		// TODO Auto-generated method stub
		Connection conn=DriverManager.getConnection(url, username, password);
		return conn;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		DB db = new DB();
		try {
			System.out.print(db.getConn().isClosed());
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
